package com.example.kt1

fun main() {
    val age: Int = 19
    val method1: () -> Unit = { println("method1") }
    method1()

    //lamda表达式可以省略
//    val method2 = { str: String ->
//        println("method2 $str")
//        true
//    }
    //等效于
    val method2: (String) -> Boolean = { str: String ->
        println("method2 $str")
        true
    }
    println(method2("haha"))


    val method04 = { str: String ->
        str.length
    }

    val method06 = { n1: Int, n2: Int ->
        n1 / n2
    }

    println(method06(6, 3))

    val method11: (() -> Unit) -> Unit = { a1: () -> Unit ->
        a1()
    }

    method11({ println("method11") })


    val method13 = { name: String, pwd: String, a1: (Boolean) -> Unit ->
        if (name == "test" && pwd == "123") {
            a1(true)
        } else {
            a1(false)
        }
    }

    /*   method13("test","1231",{
           if (it) {
               println("登录成功")
           } else {
               println("登录失败")
           }
       })*/

    method13("test", "1231") {
        if (it) {
            println("登录成功")
        } else {
            println("登录失败")
        }
    }

    val method15: (String) -> (Int) -> String = { str: String ->
        { n1: Int ->
            "我是返回的函数$n1,$str"
        }
    }

    println(method15("haha")(20))

}